package com.treetao.union.web.controller.mobile;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.treetao.union.db.model.PitchAddr;
import com.treetao.union.db.model.vo.RestResponse;
import com.treetao.union.db.service.PitchAddrService;

/**
 * 摆摊地图API
 * 
 * @Author devm
 * @date 2020年6月10日
 * @see https://gitee.com/devm/devm-mall-server
 */
@CrossOrigin(origins = "*") //处理跨域
@RestController
@RequestMapping("/mobile/pitch")
public class MobilePitchController {
	
	@Autowired
	private PitchAddrService pitchAddrService;
	
	@GetMapping("/list")
	public RestResponse list(HttpServletRequest req) {
		String sPage = req.getParameter("p");
		String kw = req.getParameter("kw");
		
		IPage<PitchAddr> page = new Page<PitchAddr>(StringUtils.isEmpty(sPage)?1:Long.valueOf(sPage),10);
		QueryWrapper<PitchAddr> q = new QueryWrapper<PitchAddr>();
		if(StringUtils.isNotEmpty(kw)) {
			q.like("pitch_address", kw).or().like("scope_business", kw);
		}
		q.select("pitch_address","pitch_address_intro","is_gov_publish","scope_business","channel_area","lng","lat","district");
		IPage<PitchAddr> ipage = pitchAddrService.page(page, q);
		return RestResponse.success(ipage.getRecords());
	}
}
